/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 */

package com.company.project.dao;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javacommon.base.BaseDaoTestCase;

import javax.annotation.Resource;

import org.apache.ibatis.executor.ErrorContext;
import org.junit.Test;

import cn.org.rapid_framework.page.Page;
import cn.org.rapid_framework.page.PageRequest;

/**
 * @author badqiu email:badqiu(a)gmail.com
 * @version 1.0
 * @since 1.0
 */


public class UserInfoDaoTest extends BaseDaoTestCase{
	
	private UserInfoDao dao;
	
	/** autowire by name */
	@Resource
	public void setUserInfoDao(UserInfoDao dao) {
		this.dao = dao;
	}

	@Override
	protected String[] getDbUnitDataFiles() {
		return new String[]{"classpath:common_testdata.xml","classpath:UserInfo_testdata.xml"};
	}
	
	@Test
	public void findByPageRequest() {
		int pageNumber = 3;
		int pageSize = 10;
		
		PageRequest<Map> pageRequest = new PageRequest(new HashMap());
		pageRequest.setPageNumber(pageNumber);
		pageRequest.setPageSize(pageSize);
		pageRequest.setSortColumns(null);
		
		pageRequest.getFilters().put("username", "");
		pageRequest.getFilters().put("password", "");
		pageRequest.getFilters().put("birthDate", "");
		pageRequest.getFilters().put("sex", "");
		pageRequest.getFilters().put("age", "");
		
		Page page = dao.findByPageRequest(pageRequest);
		System.out.println(ErrorContext.instance().toString());
		
		assertEquals(pageNumber,page.getThisPageNumber());
		assertEquals(pageSize,page.getPageSize());
		List resultList = (List)page.getResult();
		assertNotNull(resultList);
		
		
	}
	
}
